package com.xiongjie.SingleCache.Interface.impl;

import com.xiongjie.SingleCache.Interface.ISingleCache;
import com.xiongjie.SingleCache.entity.SingleCacheEntity;
import org.infinispan.Cache;

public abstract class ISingleCacheImpl implements ISingleCache {

   final private Cache<String, SingleCacheEntity> cache;

   public ISingleCacheImpl(Cache<String, SingleCacheEntity> cache) {
      this.cache = cache;
   }

   @Override
   final public SingleCacheEntity getValueByName(String name) {
      SingleCacheEntity entity = cache.get(name);
      if (entity == null) {
         entity = getSingleCacheEntity(name);
         cache.put(name, entity);
      }
      return entity;
   }

   protected abstract SingleCacheEntity getSingleCacheEntity(String name);
}
